package com.yangjun.common.comparator;

import java.util.Comparator;
import java.util.Map;

public class TargetItemComparatorByTargetArr implements Comparator<Map<String,Object>> {
	private String[] targetArr;
	public TargetItemComparatorByTargetArr(String[] targetArr){
		this.targetArr = targetArr;
	}
	private int getIndex(String value){
		int index=0;
		for(int i=0,len=targetArr.length;i<len;i++){
			if(value.equals(targetArr[i])){
				index=i;
			}
		}
		return index;
	}
	@Override
	public int compare(Map<String, Object> map1, Map<String, Object> map2) {
		String value1 = map1.get("value").toString();
		String value2 = map2.get("value").toString();
		int index1 = getIndex(value1);
		int index2 = getIndex(value2);
		return  index1>=index2?1:-1;
	}

}
